package top.jiangqiang.qianyi.web.controller.common;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.jiangqiang.qianyi.business.service.SysFileService;
import top.jiangqiang.qianyi.common.base.controller.BaseController;
import top.jiangqiang.qianyi.common.constants.GlobalConstants;


@Tag(name = "文件公共访问接口", description = "")
@RestController
@RequiredArgsConstructor
@RequestMapping(GlobalConstants.CommonRequestURLConstants.COMMON_FILE_CONTROLLER_PREFIX)
public class PublicFileController extends BaseController {

    private final SysFileService sysFileService;

    @Operation(summary = "公共存储文件访问接口", description = "无论什么底层实现，皆可通过此接口访问对应文件")
    @GetMapping(GlobalConstants.CommonRequestURLConstants.COMMON_FILE_ACCESS_API_PREFIX + "/{*fileKey}")
    public void access(@PathVariable @Length(min = 2, message = "fileKey不能为空") String fileKey) {
        sysFileService.download(fileKey, response);
    }

}
